/*
 * @Descripttion: 
 * @Author: voanit
 * @Date: 2022-06-07 18:06:00
 * @LastEditors: voanit
 * @LastEditTime: 2022-06-09 12:32:23
 */
import { SearchAction } from '@/types/store'
import { Suggestion, SearchHistory, Article, Result } from '@/types/data'
// import { getToken } from '@/utils/storage'

type SearchState = {
  suggestion: Suggestion,
  searchHistory: SearchHistory,
  results: Result
}
const initialState: SearchState = {
  suggestion: [],
  searchHistory: ['1', '2', '3', '4', '5', '6', '7', '8'], //显示历史记录的
  results: {
    page: 1,
    per_page: 10,
    total_count: 0,
    results: []

  }
}
const article = (state = initialState, action: SearchAction) => {
  console.log(action, 7);

  switch (action.type) {
    case 'search/suggestion':
      return {
        ...state,
        suggestion: action.payload
      }
    case 'search/history':
      return {
        ...state,
        searchHistory: [...action.payload]
      }
    case 'search/delHistory':
      return {
        ...state,
        searchHistory: action.payload
      }
    case 'search/delAllHistory':
      return {
        ...state,
        searchHistory: action.payload
      }
    case 'search/result':
      return {
        ...state,
        results: action.payload
      }

    default:
      return state
  }
}

export default article